package kr.ac.kongju.gedl.code.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import kr.ac.kongju.gedl.code.vo.CodeInfoVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import egovframework.rte.psl.dataaccess.EgovAbstractDAO;

@Repository("codeDAO")
public class CodeDAO extends EgovAbstractDAO{

	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	/*************************************************************************
	 * CodeInfoVO 
	 */
	
	/**
	 * registerCodeInfo
	 * @param codeInfo
	 * @return
	 * @throws SQLException
	 */
	public String registerCodeInfo(CodeInfoVO codeInfo)throws SQLException {
		String result = (String)insert("Code.registerCodeInfo", codeInfo);
		return result;
	}
	
	
	/**
	 * retrieveCodeInfo
	 * @param codeInfo
	 * @return
	 * @throws SQLException
	 */
	public CodeInfoVO retrieveCodeInfo(CodeInfoVO codeInfo)throws SQLException {
		codeInfo = ((CodeInfoVO)selectByPk("Code.retrieveCodeInfo", codeInfo));
		return codeInfo;
	}
	
	

	/**
	 * retrieveListCountCodeInfo
	 * @param codeInfo
	 * @return
	 * @throws SQLException
	 */
	public int retrieveListCountCodeInfo(CodeInfoVO searchCondition){
		int count = 0;
		try {
			count = ((Integer)getSqlMapClientTemplate().queryForObject("Code.retrieveListCountCodeInfo", searchCondition)).intValue();
			logger.debug("Code.retrieveListCountCodeInfo count:{}", count);
		} catch (Exception e) {
			logger.error("cause:{}", e.toString());   
		} 	
		return count;
	}
	
	/**
	 * retrieveListCodeInfo
	 * @param codeInfo
	 * @return
	 * @throws SQLException
	 */
	@SuppressWarnings("unchecked")
	public List<CodeInfoVO> retrieveListCodeInfo(CodeInfoVO searchCondition)throws SQLException {
		
		List<CodeInfoVO> list = getSqlMapClientTemplate().queryForList("Code.retrieveListCodeInfo", searchCondition);
		logger.debug("Code.retrieveListCodeInfo size:{}", list.size());
		return list;
	}
       
}
